<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jspf/taglibs.jspf"%>
<script type="text/javascript" src="/js/imageAuto.js"></script>
<script type="text/javascript" src="/js/bootstrap/dist/js/bootstrapValidator.js"></script>
<div class="aside-dialog">
    <div class="aside-content" style="height:600px;overflow-y:auto;">
        <div class="aside-header" ng-show="title">
            <button id="newCreativesClose" class="close" type="button" >×</button>
            <h4 class="aside-title">新建广告创意</h4>
        </div>
        <div class="aside-body" ng-show="content">
            <form id="creativsAddForm"  class="form-horizontal ng-scope ng-valid ng-dirty ng-pristine" method="post">
                <div class="form-group">
                    <label class="col-sm-4 control-label">广告创意名称</label>
                    <div class="col-sm-4">
                        <input  id="creativeName" type="text" class="form-control"  name="creativeName" required>
                        <!--修复enter按键提交表单-->
                        <input type="text"  style="display: none;">
                    </div>
                </div>
                <c:forEach items="${crtSizeMediumMenus }" var="crtSizeMediumMenu">
                    <input id="crtSize-id-${crtSizeMediumMenu.crtSize}" type="hidden" value='${crtSizeMediumMenu.format}'/>
                </c:forEach>
                <div class="form-group">
                    <label class="col-sm-4 control-label">创意尺寸</label>
                    <div class="col-sm-4">
                        <select id="crtSizeMediumMenuId" name="crtSizeMediumMenuId" class="form-control">
                            <option value="请选择">请选择...</option>
                            <c:forEach items="${crtSizeMediumMenus }" var="crtSizeMediumMenu">
                                <option value="${crtSizeMediumMenu.crtSize}">${crtSizeMediumMenu.crtSizeDetail}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="generate-model"></div>
            </form>
        </div>
        <div class="aside-footer modal-footer-btn add-ads-advert-btn">
            <lable id="doNewCreatives"  class="btn btn-primary"  >提 交</lable>
            <lable id="backCreatives"  class="btn btn-default"  >取 消</lable>
        </div>
    </div>
</div>
<script type="text/javascript"  src="/js/plugins/uploader/jquery.uploadify.js"></script>
<script>
    $().ready(function() {
        //关闭弹框
        $("#backCreatives").click(function(){
            $("#newCreatives").modal('hide')
        });

        $("#newCreativesClose").click(function(){

            $("#newCreatives").modal('hide')
        });

        $('#crtSizeMediumMenuId').on('change', function() {
            // 清空区域
            $('.generate-model').empty();
            // format banner图片上传格式
            var data = '', bannerFormat = '',shareFormat = '', trademarkFormat= '';
            var id = $(this).find("option:selected").val();
            if (id) {
                data = JSON.parse($('#crtSize-id-'+id).val());
                console.log(data)
            }
            if (data) {
                // 判断初始化自定义值
                if (data.value.banner_path.format && data.value.banner_path.format != "") {
                    bannerFormat += bannerFormat+'支持PNG、JPG、JEPG'; // banner图片上传格式
                }
                if (data.value.banner_path.max == 0) {
                    var max = '不限大小';
                } else {
                    var max = data.value.banner_path.max+'KB以内';
                }

                var t = simpleTpl();
                // 判断value 生成不同类型的页面区块 现在的
                switch(data.type)
                {
                    case 1:
                        t._('<div class="form-group">')
                        t._('<label class="col-sm-4 control-label">上传Banner</label>')
                        t._('<div class="col-sm-4">')
                        t._('<div class="show-uploaded-photo"></div>')
                        t._('<div class="upload-hidden-container"></div>')
                        t._('<div class="upload-file-container">')
                        t._('<input type="file" id="bannerUpload" class="uploadFile-input" data-width='+data.value.banner_path.image_width+' data-height='+data.value.banner_path.image_height+' data-format='+data.value.banner_path.format+' data-size='+data.value.banner_path.max+'  data-num='+data.value.banner_path.number+' data-type="banner" form-control">')
                        t._('<input type="hidden" name="sitesetType" value='+data.siteset_type+' />')
                        t._('<input type="hidden" name="crtSizeDetail" value='+data.crt_size_detail+' />')
                        t._('<small class="text-muted" style="float:left;">图片规格: '+data.value.banner_path.image_width+'*'+data.value.banner_path.image_height+'像素，'+max+'，'+bannerFormat+'，<span style="color:#bd4848;">(需要上传'+data.value.banner_path.number+'张)</span></small>')
                        t._('</div>')
                        t._('</div>')
                        t._('</div>')

                        t._('<div class="form-group">')
                        t._('<label class="col-sm-4 control-label">创意文案</label>')
                        t._('<div class="col-sm-4">')
                        t._('<div class="upload-txt-container">')
                        t._('<textarea class="form-control" id="creativeCopywriter" name="creativeCopywriter" rows='+data.value.creative_copywriter.rows+' minlength='+data.value.creative_copywriter.min+' maxlength='+data.value.creative_copywriter.max+' required></textarea>')
                        t._('<span class="validate-txt">'+data.value.creative_copywriter.min+'~'+data.value.creative_copywriter.max+'</span>')
                        t._('</div>')
                        t._('</div>')
                        t._('</div>')


                        t._('<div class="form-group">')
                        t._('<label class="col-sm-4 control-label">上传商标</label>')
                        t._('<div class="col-sm-4">')
                        t._('<div class="show-uploaded-photo"></div>')
                        t._('<div class="upload-hidden-container"></div>')
                        t._('<div class="upload-file-container">')
                        t._('<input type="file" id="trademarkUpload" class="uploadFile-input" data-width='+data.value.trademark_path.image_width+' data-height='+data.value.trademark_path.image_height+' data-size='+data.value.trademark_path.max+' data-num='+data.value.trademark_path.number+' data-type="trademark" form-control">')
                        // t._('<button class="uploadFile-btn btn  btn-primary" >上传图片</button>')
                        t._('<small class="text-muted" style="float:left;">图片规格: '+data.value.trademark_path.image_width+'*'+data.value.trademark_path.image_height+'像素</small>')
                        t._('</div>')
                        t._('</div>')
                        t._('</div>')

                        t._('<div class="form-group">')
                        t._('<label class="col-sm-4 control-label">商标名称</label>')
                        t._('<div class="col-sm-4">')
                        t._('<div class="upload-txt-container">')
                        t._('<textarea class="form-control" id="trademarkName" name="trademarkName" rows='+data.value.trademark_name.rows+' minlength='+data.value.trademark_name.min+' maxlength='+data.value.trademark_name.max+' required></textarea>')
                        t._('<span class="validate-txt">'+data.value.trademark_name.min+'~'+data.value.trademark_name.max+'</span>')
                        t._('</div>')
                        t._('</div>')
                        t._('</div>')

                        break;
                    case 2:
                        t._('<div class="form-group">')
                        t._('<label class="col-sm-4 control-label">上传Banner</label>')
                        t._('<div class="col-sm-4">')
                        t._('<div class="show-uploaded-photo"></div>')
                        t._('<div class="upload-hidden-container"></div>')
                        t._('<div class="upload-file-container">')
                        t._('<input type="file" id="bannerUpload" class="uploadFile-input" data-width='+data.value.banner_path.image_width+' data-height='+data.value.banner_path.image_height+' data-format='+data.value.banner_path.format+' data-num='+data.value.banner_path.number+' data-size='+data.value.banner_path.max+' data-type="banner" form-control">')
                        t._('<input type="hidden" name="sitesetType" value='+data.siteset_type+' />')
                        t._('<input type="hidden" name="crtSizeDetail" value='+data.crt_size_detail+' />')
                        t._('<small class="text-muted" style="float:left;">图片规格: '+data.value.banner_path.image_width+'*'+data.value.banner_path.image_height+'像素，'+max+'，'+bannerFormat+'，<span style="color:#bd4848;">(需要上传'+data.value.banner_path.number+'张)</span></small>')
                        t._('</div>')
                        t._('</div>')
                        t._('</div>')

                        t._('<div class="form-group">')
                        t._('<label class="col-sm-4 control-label">创意文案</label>')
                        t._('<div class="col-sm-4">')
                        t._('<div class="upload-txt-container">')
                        t._('<textarea class="form-control" id="creativeCopywriter" name="creativeCopywriter" rows='+data.value.creative_copywriter.rows+' minlength='+data.value.creative_copywriter.min+' maxlength='+data.value.creative_copywriter.max+' required></textarea>')
                        t._('<span class="validate-txt">'+data.value.creative_copywriter.min+'~'+data.value.creative_copywriter.max+'</span>')
                        t._('</div>')
                        t._('</div>')
                        t._('</div>')
                        break;
                    case 3:
                        t._('<div class="form-group">')
                        t._('<label class="col-sm-4 control-label">上传Banner</label>')
                        t._('<div class="col-sm-4">')
                        t._('<div class="show-uploaded-photo"></div>')
                        t._('<div class="upload-hidden-container"></div>')
                        t._('<div class="upload-file-container">')
                        t._('<input type="file" id="bannerUpload" class="uploadFile-input" data-width='+data.value.banner_path.image_width+' data-height='+data.value.banner_path.image_height+'  data-format='+data.value.banner_path.format+' data-size='+data.value.banner_path.max+' data-num='+data.value.banner_path.number+' data-type="banner" form-control">')
                        t._('<input type="hidden" name="sitesetType" value='+data.siteset_type+' />')
                        t._('<input type="hidden" name="crtSizeDetail" value='+data.crt_size_detail+' />')
                        t._('<small class="text-muted" style="float:left;">图片规格: '+data.value.banner_path.image_width+'*'+data.value.banner_path.image_height+'像素，'+max+'，'+bannerFormat+'，<span style="color:#bd4848;">(需要上传'+data.value.banner_path.number+'张)</span></small>')
                        t._('</div>')
                        t._('</div>')
                        t._('</div>')

                        t._('<div class="form-group">')
                        t._('<label class="col-sm-4 control-label">分享图片</label>')
                        t._('<div class="col-sm-4">')
                        t._('<div class="show-uploaded-photo"></div>')
                        t._('<div class="upload-hidden-container"></div>')
                        t._('<div class="upload-file-container">')
                        t._('<input type="file" id="shareUpload" class="uploadFile-input" data-width='+data.value.share_path.image_width+' data-height='+data.value.share_path.image_height+' data-size='+data.value.share_path.max+' data-num='+data.value.share_path.number+' data-type="share" form-control">')
                        // t._('<button class="uploadFile-btn btn  btn-primary" >上传图片</button>')
                        t._('<small class="text-muted" style="float:left;">图片规格: '+data.value.share_path.image_width+'*'+data.value.share_path.image_height+'像素</small>')
                        t._('</div>')
                        t._('</div>')
                        t._('</div>')

                        t._('<div class="form-group">')
                        t._('<label class="col-sm-4 control-label">分享标题</label>')
                        t._('<div class="col-sm-4">')
                        t._('<div class="upload-txt-container">')
                        t._('<textarea class="form-control" id="shareTitle" name="shareTitle" rows="3" minlength='+data.value.share_title.min+' maxlength='+data.value.share_title.max+' required></textarea>')
                        t._('<span class="validate-txt">'+data.value.share_title.min+'~'+data.value.share_title.max+'</span>')
                        t._('</div>')
                        t._('</div>')
                        t._('</div>')

                        t._('<div class="form-group">')
                        t._('<label class="col-sm-4 control-label">分享描述</label>')
                        t._('<div class="col-sm-4">')
                        t._('<div class="upload-txt-container">')
                        t._('<textarea class="form-control" id="shareDescribe" name="shareDescribe" rows="3" minlength='+data.value.share_describe.min+' maxlength='+data.value.share_describe.max+' required></textarea>')
                        t._('<span class="validate-txt">0~'+data.value.share_describe.max+'</span>')
                        t._('</div>')
                        t._('</div>')
                        t._('</div>')
                        break;
                    case 4:
                        t._('<div class="form-group">')
                        t._('<label class="col-sm-4 control-label">上传Banner</label>')
                        t._('<div class="col-sm-4">')
                        t._('<div class="show-uploaded-photo"></div>')
                        t._('<div class="upload-hidden-container"></div>')
                        t._('<div class="upload-file-container">')
                        t._('<input type="file" id="bannerUpload" class="uploadFile-input" data-width='+data.value.banner_path.image_width+' data-height='+data.value.banner_path.image_height+' data-format='+data.value.banner_path.format+' data-size='+data.value.banner_path.max+' data-num='+data.value.banner_path.number+' data-type="banner" form-control">')
                        t._('<input type="hidden" name="sitesetType" value='+data.siteset_type+' />')
                        t._('<input type="hidden" name="crtSizeDetail" value='+data.crt_size_detail+' />')
                        t._('<small class="text-muted" style="float:left;">图片规格: '+data.value.banner_path.image_width+'*'+data.value.banner_path.image_height+'像素，'+max+'，'+bannerFormat+'，<span style="color:#bd4848;">(需要上传'+data.value.banner_path.number+'张)</span></small>')
                        t._('</div>')
                        t._('</div>')
                        t._('</div>')
                        break;
                    case 5:
                        t._('<div class="form-group">')
                        t._('<label class="col-sm-4 control-label">上传Banner</label>')
                        t._('<div class="col-sm-4">')
                        t._('<div class="show-uploaded-photo"></div>')
                        t._('<div class="upload-hidden-container"></div>')
                        t._('<div class="upload-file-container">')
                        t._('<input type="file" id="bannerUpload" class="uploadFile-input" data-width='+data.value.banner_path.image_width+' data-height='+data.value.banner_path.image_height+' data-format='+data.value.banner_path.format+' data-size='+data.value.banner_path.max+'  data-num='+data.value.banner_path.number+' data-type="banner" form-control">')
                        t._('<input type="hidden" name="sitesetType" value='+data.siteset_type+' />')
                        t._('<input type="hidden" name="crtSizeDetail" value='+data.crt_size_detail+' />')
                        t._('<small class="text-muted" style="float:left;">图片规格: '+data.value.banner_path.image_width+'*'+data.value.banner_path.image_height+'像素，'+max+'，'+bannerFormat+'，<span style="color:#bd4848;">(需要上传'+data.value.banner_path.number+'张)</span></small>')
                        t._('</div>')
                        t._('</div>')
                        t._('</div>')

                        t._('<div class="form-group">')
                        t._('<label class="col-sm-4 control-label">创意文案</label>')
                        t._('<div class="col-sm-4">')
                        t._('<div class="upload-txt-container">')
                        t._('<textarea class="form-control" id="creativeCopywriter" name="creativeCopywriter" rows='+data.value.creative_copywriter.rows+' minlength='+data.value.creative_copywriter.min+' maxlength='+data.value.creative_copywriter.max+' required></textarea>')
                        t._('<span class="validate-txt">'+data.value.creative_copywriter.min+'~'+data.value.creative_copywriter.max+'</span>')
                        t._('</div>')
                        t._('</div>')
                        t._('</div>')

                        t._('<div class="form-group">')
                        t._('<label class="col-sm-4 control-label">商标名称</label>')
                        t._('<div class="col-sm-4">')
                        t._('<div class="upload-txt-container">')
                        t._('<textarea class="form-control" id="trademarkName" name="trademarkName" rows='+data.value.trademark_name.rows+' minlength='+data.value.trademark_name.min+' maxlength='+data.value.trademark_name.max+' required></textarea>')
                        t._('<span class="validate-txt">'+data.value.trademark_name.min+'~'+data.value.trademark_name.max+'</span>')
                        t._('</div>')
                        t._('</div>')
                        t._('</div>')
                        break;
                }
                $('.generate-model').append(t.toString());



                // 动态验证
                // 创意文案
                $("#creativsAddForm").bootstrapValidator('addField','creativeCopywriter',{
                    validators: {
                        notEmpty: {
                            message:'请输入创意文案'
                        },
                        stringLength: {
                            min:$('.generate-model').find('#creativeCopywriter').attr('minlength'),
                            max:$('.generate-model').find('#creativeCopywriter').attr('maxlength'),
                            message: '分享标题最短'+$('.generate-model').find('#creativeCopywriter').attr('minlength')+'个字符最长'+$('.generate-model').find('#creativeCopywriter').attr('maxlength')+'个字符'
                        }
                    }
                });

                // 分享标题
                $("#creativsAddForm").bootstrapValidator('addField','shareTitle',{
                    validators: {
                        notEmpty: {
                            message:'请输入分享标题'
                        },
                        stringLength: {
                            min:$('.generate-model').find('#shareTitle').attr('minlength'),
                            max:$('.generate-model').find('#shareTitle').attr('maxlength'),
                            message: '分享标题最短'+$('.generate-model').find('#shareTitle').attr('minlength')+'个字符最长'+$('.generate-model').find('#shareTitle').attr('maxlength')+'个字符'
                        }
                    }
                });

                // 分享描述
                $("#creativsAddForm").bootstrapValidator('addField','shareDescribe',{
                    validators: {
                        notEmpty: {
                            message:'请输入分享描述'
                        },
                        stringLength: {
                            min:$('.generate-model').find('#shareDescribe').attr('minlength'),
                            max:$('.generate-model').find('#shareDescribe').attr('maxlength'),
                            message: '分享描述最短'+$('.generate-model').find('#shareDescribe').attr('minlength')+'个字符最长'+$('.generate-model').find('#shareDescribe').attr('maxlength')+'个字符'
                        }
                    }
                });

                // 商标名称
                $("#creativsAddForm").bootstrapValidator('addField','trademarkName',{
                    validators: {
                        notEmpty: {
                            message:'请输入商标名称'
                        },
                        stringLength: {
                            min:$('.generate-model').find('#trademarkName').attr('minlength'),
                            max:$('.generate-model').find('#trademarkName').attr('maxlength'),
                            message: '商标名称最短'+$('.generate-model').find('#trademarkName').attr('minlength')+'个字符最长'+$('.generate-model').find('#trademarkName').attr('maxlength')+'个字符'
                        },
                        regexp: {
                            regexp:/^[^`~%!@#^=''?~！@#￥……&——‘”“'？*()（），,。.、;:"><|/\\$%\^]*$/,
                            message: '商标名称不能含有标点符号'
                        }
                    }
                });

            }

            // 遍历有需要上传的元素
            $('.generate-model').find('.uploadFile-input').each(function(i, item) {
                var $the_data=$(this)
                // 获取上传参数
                var width = $(this).data('width'),
                        height = $(this).data('height'),
                        num = $(this).data('num'),
                        size = $(this).data('size'),
                        format = $(this).data('format'),
                        type = $(this).data('type');
                var id = $(this).attr('id');
                console.log(size);
                if (size == 0) {
                    size = 1024*1024;
                }else{
                    size =size*1024;
                }
                console.log(size);
                // 初始化图片宽高
                updatedCrtSize(type,width,height,num,size);
                //重新初始广告创意图片上传
                $.mitian.initCreativeUploader(
                        '#'+id,
                        format,
                        size,
                        num,
                        imageEditUploadStart,
                        imageEditUploadSuccess);


                // 上传banner图片
                var imgWidth = '', imgHeight = '', bannerWidth = '', bannerHeight = '', shareWidth = '', shareHeight ='';
                //图片上传
                function imageEditUploadStart() {
                    //$('.generate-model').find('.uploadFile-input').each(function(i, item) {
                    // 获取上传参数
                    var width = $the_data.data('width'),
                            height = $the_data.data('height'),
                            num = $the_data.data('num'),
                            size = $the_data.data('size'),
                            type = $the_data.data('type');
                    format = $the_data.data('format');
                    var id = $the_data.attr('id');

                    /* if (type == 'banner') {
                     imgWidth = bannerWidth;
                     imgHeight = bannerHeight;
                     alert('banner'+ imgWidth + 'zzzz'+ imgHeight);
                     }
                     if (type == 'share') {
                     imgWidth = shareWidth;
                     imgHeight = shareHeight;
                     }*/
                    console.log(width+'x'+height)
                    console.log('#'+id);
                    $('#'+id).uploadifySettings('scriptData', {
                        'imgHeight' : height,
                        'imgWidth' : width,
                        'fixName' : format,
                        'imgType' : 3,
                        'status':1
                    });
                    //});
                }




            });

        });



        // 上传成功
        function imageEditUploadSuccess(event, queueID, fileObj, response) {
            console.log(event);
            var res = JSON.parse(response);
            if(res.result=="fail"){
                alert("上传的图片尺寸不合适")
            }

            if (res.result == 'ok') {
                console.log(event.target.id);
                console.log(response);
                var obj = $('#'+event.target.id);
                var type = obj.data('type');
                var num = obj.data('num');
                // banner
                if (type == 'banner') {
                    var len  = obj.closest('.form-group').find('.upload-i-co').length;

                    if (num > 1) {
                        if (len < num) {
                            obj.closest('.form-group').find('.upload-hidden-container').addClass('bannerHidden').append('<div class="upload-i-co"><input type="text" hidden="hidden" class="bannerPathInput bannerPathInputa" id="bannerPath'+(len+1)+'" name="bannerPath'+(len+1)+'" data-id='+(len+1)+' value='+res.picOrignalPath+'><input type="text" hidden="hidden" class="bannerPathInput bannerPathInputb" id="bannerShowPath'+(len+1)+'" name="bannerShowPath'+(len+1)+'" data-id='+(len+1)+' value='+res.picSavePath+'></div>');  
                        }else {
                            showMsg('error','请删除图片再上传！')
                            return false;
                        }
                    }
                    else {
                        if (len <= 0) {
                            obj.closest('.form-group').find('.upload-hidden-container').append('<div class="upload-i-co"><input type="text" hidden="hidden" class="bannerPathInput" id="bannerPath'+(len+1)+'" name="bannerPath'+(len+1)+'" value='+res.picOrignalPath+'><input type="text" hidden="hidden" class="bannerPathInput" id="bannerShowPath'+(len+1)+'" name="bannerShowPath'+(len+1)+'" value='+res.picSavePath+'></div>');
                        }else {
                            showMsg('error','请删除图片再上传！')
                            return false;
                        }
                    }
                }
                // 分享
                if (type == 'share') {
                    var len  = obj.closest('.form-group').find('.upload-i-co').length;
                    if (len <= 0) {
                        obj.closest('.form-group').find('.upload-hidden-container').append('<div class="upload-i-co"><input type="text" hidden="hidden" class="sharePathInput" id="sharePath" name="sharePath" value='+res.picOrignalPath+'><input type="text" hidden="hidden" class="sharePathInput" id="shareShowPath" name="shareShowPath" value='+res.picSavePath+'></div>');
                    } else {
                        showMsg('error','请删除图片再上传！')
                        return false;
                    }

                }

                // 商标
                if (type == 'trademark') {
                    var len  = obj.closest('.form-group').find('.trademarkPathInput').length;
                    if (len == 0) {
                        obj.closest('.form-group').find('.upload-hidden-container').append('<div class="upload-i-co"><input type="text" hidden="hidden" class="trademarkPathInput" id="trademarkPath" name="trademarkPath" value='+res.picOrignalPath+'><input type="text" hidden="hidden" class="trademarkPathInput" id="trademarkShowPath" name="trademarkShowPath" value='+res.picSavePath+'></div>');
                    } else {
                        showMsg('error','请删除图片再上传！')
                        return false;
                    }
                }

                var uploadPhoto = $('#'+event.target.id).closest('.form-group').find('.show-uploaded-photo');
                uploadPhoto.append('<div class="del-img"><i class="del-icon icon glyphicon glyphicon-remove"></i><img src="'+res.picOrignalPath+'"  /></div>')

                uploadPhoto.find('.del-icon').on('click', function() {
                    var index = $(this).closest('.del-img').index();
                    $(this).closest('.show-uploaded-photo').next('.upload-hidden-container').find('.upload-i-co').eq(index).remove();
                    $(this).closest('.show-uploaded-photo').find('.del-img').eq(index).remove();
                });
            }
        }
        //更新图片尺寸
        function updatedCrtSize(type,width,height,num,size){
            console.log(type);
            switch (type)
            {
                case 'banner':
                    bannerWidth = width || '';
                    bannerHeight = height || '';
                    break;
                case 'share':
                    shareWidth = width || '';
                    shareHeight = height || '';
                    break;
            }
        }





        $("#doNewCreatives").click(function(){
            $('#creativsAddForm').bootstrapValidator('validate');
        });


        $('#creativsAddForm').bootstrapValidator({
            fields: {
                // 创意名称
                creativeName: {
                    validators: {
                        notEmpty:{
                            message:'请输入广告创意名称'
                        },
                        stringLength:{
                            max: 40,
                            message: '广告创意名称最长40个字符'
                        }
                    }
                },
            }

        }).on('success.form.bv', function (e) {

            var bannerLen =  $('.generate-model').find('.bannerPathInput').length;
            var bannerNum = $('.generate-model').find('#bannerUpload').eq(0).data('num');
            if (bannerNum != null &&bannerLen != (bannerNum*2)) {
                showMsg("error","banner图片需要传满"+bannerNum+'张！');
                return false;
            }

            var shareLen =  $('.generate-model').find('.sharePathInput').length;
            var shareNum = $('.generate-model').find('#shareUpload').eq(0).data('num');
            if (shareNum!= null &&shareLen != (bannerNum*2)) {
                showMsg("error","分享图片需要传满"+shareNum+'张！');
                return false;
            }

            var trademarkLen =  $('.generate-model').find('.trademarkPathInput').length;
            var trademarkNum = $('.generate-model').find('#trademarkUpload').eq(0).data('num');
            if (trademarkNum !=null && trademarkLen != (trademarkNum*2)) {
                showMsg("error","商标图片需要传满"+trademarkNum+'张！');
                return false;
            }

            var len = $('.bannerHidden').find('.upload-i-co').length;
            for (var i = 0; i < len; i++) {
                $('.bannerHidden').find('.upload-i-co').eq(i).find('.bannerPathInputa').attr({'id':'bannerPath'+(i+1),'name':'bannerPath'+(i+1)});
                $('.bannerHidden').find('.upload-i-co').eq(i).find('.bannerPathInputb').attr({'id':'bannerShowPath'+(i+1),'name':'bannerShowPath'+(i+1)});
            }

            $.ajax({
                url: '/front_creatives/add',
                type: 'POST',
                data: $('#creativsAddForm').serialize(),
                dataType: 'json',
                async: false,
                success: function (data, status, xhr) {
                    showMsg("success", "添加成功")
                    $("#newCreatives").modal("hide");
                }
            });
            return false;//防止form表单提交
        });
    })
</script>

